package com.sq.shortlink.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sq.shortlink.project.common.convension.result.Result;
import com.sq.shortlink.project.common.convension.result.Results;
import com.sq.shortlink.project.dto.req.RecycleBinRecoverReqDTO;
import com.sq.shortlink.project.dto.req.RecycleBinRemoveDTO;
import com.sq.shortlink.project.dto.req.RecycleBinSaveReqDTO;
import com.sq.shortlink.project.dto.req.ShortLinkRecycleBinPageReqDTO;
import com.sq.shortlink.project.dto.resp.ShortLinkPageRespDTO;
import com.sq.shortlink.project.service.RecycleBinService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 短链接回收站控制层
 * @author quan
 */
@RestController
@RequiredArgsConstructor
public class RecycleBinController {

    private final RecycleBinService recycleBinService;

    /**
     * 保存到回收站
     * @param requestParam 保存回收站请求参数
     */
    @PostMapping("/api/short-link/v1/recycle-bin/save")
    public Result<Void> saveRecycleBin(@RequestBody RecycleBinSaveReqDTO requestParam){
        recycleBinService.saveRecycleBin(requestParam);
        return Results.success();
    }

    /**
     * 回收站中短链接分页查询
     * @param requestParam 分页查询请求参数
     * @return 分页查询结果
     */
    @PostMapping("/api/short-link/v1/recycle-bin/page")
    public Result<IPage<ShortLinkPageRespDTO>> pageShortLinkRecycleBin(@RequestBody ShortLinkRecycleBinPageReqDTO requestParam) {
        return Results.success(recycleBinService.pageShortLinkRecycleBin(requestParam));
    }

    /**
     * 恢复回收站中的短链接
     * @param requestParam 恢复的短链接参数
     */
    @PostMapping("/api/short-link/v1/recycle-bin/recover")
    public Result<Void> recycleBinRecover(@RequestBody RecycleBinRecoverReqDTO requestParam){
        recycleBinService.recycleBinRecover(requestParam);
        return Results.success();
    }

    @PostMapping("/api/short-link/v1/recycle-bin/remove")
    public Result<Void> recycleBinRemove(@RequestBody RecycleBinRemoveDTO requestParam){
        recycleBinService.recycleBinRemove(requestParam);
        return Results.success();
    }

}
